package com.ipdatacloud.searchtest.util.result;


import java.util.ArrayList;



class Proxy {
    private final String result;
    private String proxyType;
    private String proxyTime;

    Proxy(String result) {
        this.result = result;
        parseProxy();
    }

    void parseProxy() {
        String[] infos = this.result.split("\\|", -1);
        if (infos.length != 3) {
            System.out.println("查询结果格式错误或离线库非代理v2版本库");
            proxyTime = "";
            proxyType = "";
            return;
        }
        if (infos[0].equals("否")) {
            this.proxyType = "不是代理";
            this.proxyTime = "";
        } else {
            String[] proxyTypes = infos[1].split(",");
            ArrayList<String> p = new ArrayList<>();
            for (String type : proxyTypes) {
                if (!type.isEmpty()) {
                    p.add(type);
                }
            }
            proxyType = String.join("|", p);
            proxyTime = infos[2];
        }

    }

    public String getProxyType() {
        return proxyType;
    }

    public String getProxyTime() {
        return proxyTime;
    }
}

class Scenes {
    private final String result;
    private String scenes;

    public String getResult() {
        return result;
    }

    public String getScenes() {
        return scenes;
    }

    Scenes(String result) {
        this.result = result;
        parseScene();
    }

    private void parseScene() {
        String[] infos = result.split("\\|", -1);
        if (infos.length != 1) throw new IllegalArgumentException("查询结果格式错误或离线库非场景库");
        switch (infos[0]) {
            case "COM":
                this.scenes = "商业公司";
                break;
            case "EDU":
                this.scenes = "教育机构";
                break;
            case "GTW":
                this.scenes = "企业专线";
                break;
            case "GOV":
                this.scenes = "政府机构";
                break;
            case "NET":
                this.scenes = "基础设施";
                break;
            case "ORG":
                this.scenes = "组织机构";
                break;
            case "DYN":
                this.scenes = "家庭宽带";
                break;
            case "IDC":
                this.scenes = "数据中心";
                break;
            case "MOB":
                this.scenes = "移动网络";
                break;
            case "CDN":
                this.scenes = "内容分发";
                break;
            case "DNS":
                this.scenes = "域名解析";
                break;
            case "BOGON":
                this.scenes = "保留";
                break;
            default:
                this.scenes = "-";  // 处理未匹配的情况
                break;
        }


    }
}


class Location {
    private String continent;//洲
    private String country;//国家/地区
    private String province;//省份
    private String city;//城市
    private String district;//区县
    private String isp;//运营商
    private String areaCode;//区域代码
    private String countryEnglish;//国家/地区英文
    private String countryCode;//国家/地区英文简写
    private String longitude;//经度
    private String latitude;       //纬度
    private String elevation;      //海拔
    private String zipCode;      //邮编
    private String cityCode;    //城市代码
    private String weatherStation; //气象站
    private String asn;
    private String preserve;    //预留
    private String street;      //街道
    private String timeZone;    //时区

    private final String result;

    public String getContinent() {
        return continent;
    }

    public String getCountry() {
        return country;
    }

    public String getProvince() {
        return province;
    }

    public String getCity() {
        return city;
    }

    public String getDistrict() {
        return district;
    }

    public String getIsp() {
        return isp;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public String getCountryEnglish() {
        return countryEnglish;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public String getLongitude() {
        return longitude;
    }

    public String getLatitude() {
        return latitude;
    }

    public String getElevation() {
        return elevation;
    }

    public String getZipCode() {
        return zipCode;
    }

    public String getCityCode() {
        return cityCode;
    }

    public String getWeatherStation() {
        return weatherStation;
    }

    public String getAsn() {
        return asn;
    }

    public String getPreserve() {
        return preserve;
    }

    public String getStreet() {
        return street;
    }

    public String getTimeZone() {
        return timeZone;
    }

    public Location(String result) {
        this.result = result;
        parseLocation();
    }

    private void parseLocation() {
        String[] infos = result.split("\\|", -1);
        if (infos.length != 19) throw new IllegalArgumentException("查询结果格式错误或离线库非归属地库");
        this.continent = infos[0];
        this.country = infos[1];
        this.province = infos[2];
        this.city = infos[3];
        this.district = infos[4];
        this.isp = infos[5];
        this.areaCode = infos[6];
        this.countryEnglish = infos[7];
        this.countryCode = infos[8];
        this.longitude = infos[9];
        this.latitude = infos[10];
        this.elevation = infos[11];
        this.zipCode = infos[12];
        this.cityCode = infos[13];
        this.weatherStation = infos[14];
        this.asn = infos[15];
        this.preserve = infos[16];
        this.street = infos[17];
        this.timeZone = infos[18];
    }

    @Override
    public String toString() {
        return "Location{" +
                "continent='" + continent + '\'' +
                ", country='" + country + '\'' +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", district='" + district + '\'' +
                ", isp='" + isp + '\'' +
                ", areaCode='" + areaCode + '\'' +
                ", countryEnglish='" + countryEnglish + '\'' +
                ", countryCode='" + countryCode + '\'' +
                ", longitude='" + longitude + '\'' +
                ", latitude='" + latitude + '\'' +
                ", elevation='" + elevation + '\'' +
                ", zipCode='" + zipCode + '\'' +
                ", cityCode='" + cityCode + '\'' +
                ", weatherStation='" + weatherStation + '\'' +
                ", asn='" + asn + '\'' +
                ", preserve='" + preserve + '\'' +
                ", street='" + street + '\'' +
                ", timeZone='" + timeZone + '\'' +
                '}';
    }
}
